// pages/vipList/vipList.js
var app = getApp();
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    vipIndex:0,
    info: [
      // { id: 6, mid: 1, title: "测试", money: "1000.00", score: "20.00", month: 1, describe: "", displayorder: 1 },
      // { id: 7, mid: 1, title: "普通会员", money: "99.00", score: "99.00", month: 12, describe: "等级说明↵普通会员享受", displayorder: 0 },
      // { id: 7, mid: 1, title: "白银会员", money: "99.00", score: "99.00", month: 12, describe: "等级说明↵普通会员享受", displayorder: 0 },
      // { id: 7, mid: 1, title: "黄金会员", money: "99.00", score: "99.00", month: 12, describe: "等级说明↵普通会员享受", displayorder: 0 },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.siteInfo.shoppath + 'viplist',
      method: "post",
      data: {
        uid: app.siteInfo.uid,
        pid: app.siteInfo.pid,
        com_part_id: app.siteInfo.com_part_id,
      },
      success: function (res) {
        var arr = res.data.info
        if(arr.length<1){
          wx.showModal({
            title: '成为会员',
            content: '暂未设置会员等级信息',
            success:function(res){
              wx.navigateTo({
                url: '/pages/mine/mine',
              })
            }
          })
        }else{
          var article = res.data.info[0].describe
          WxParse.wxParse('article', 'html', article, that, 0);
          // res.data.content = article;
          that.setData({
            info: res.data.info,
            describe: article,
            choseid: res.data.info[0].id,
          })
        }
        
      }
    })
  },
  chose :function(e){
    console.log(e)
    var that = this
    var index = e.target.dataset.index
    var info = this.data.info;
    var article = info[index].describe
    WxParse.wxParse('article', 'html', article, that, 0);
    this.setData({
      vipIndex: index,
      describe: article,
      choseid: info[index].id,
    })
  },
  paymoney:function(){
    var that = this;
    var id = that.data.choseid;
    wx.request({
      url: app.siteInfo.shoppath + 'create_viporder',
      method: "post",
      data: {
        id: id,
        pid: app.siteInfo.pid,
        uid: app.siteInfo.uid,
        com_part_id: app.siteInfo.com_part_id,
      },
      success: function (res) {
        if (res.data.code == 200) {
          wx.request({
            url: app.siteInfo.shoppath + 'payvip',
            data: {
              orderid: res.data.orderid,
              pid: app.siteInfo.pid,
              uid: app.siteInfo.uid,
              com_part_id: app.siteInfo.com_part_id
            },
            method: 'post',
            success: function (res) {
              console.log(res);
              // return;
              wx.requestPayment({
                'appId': res.data.appId,
                'timeStamp': res.data.timeStamp,
                'nonceStr': res.data.nonceStr,
                'package': res.data.package,
                'signType': res.data.signType,
                'paySign': res.data.paySign,
                'success': function (res) {
                  console.log(res);

                },
                'fail': function (res) {
                  console.log(res);
                },
                complete: function () {
                  wx.navigateTo({
                    url: '/pages/mine/mine',
                  })
                }
              })
            }
          })

        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
        }

      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})